package com.ykdl.member.views;

import com.ykdl.member.kid.R;
import com.ykdl.member.kid.util.MobileUtils;
import com.ykdl.member.kid.widget.AsyncImageView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class DoctorTalkChildItem extends LinearLayout {

	private Context context;
	private LinearLayout view;
	public RelativeLayout rl_doctor_talk_child;
	public AsyncImageView iv_doctor_talk_child;
	public TextView tv_doctor_talk_child;
	public int res;
	public DoctorTalkChildItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(res);
	}

	public DoctorTalkChildItem(Context context) {
		super(context);
		initView(res);
	}
   
	public DoctorTalkChildItem(Context context, int res){
		super(context);
		this.context = context;
		initView(res);
		
	}

	private void initView(int res) {
		
		int screen_width = MobileUtils.getScreenWidthIntPx();
		int item_width = (screen_width - MobileUtils.dpToPx(12)) / 2;
		int item_iamge_width = (int)(item_width / 1.5);
		
		
		view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.doctor_talk_child_item_view, null);
		LayoutParams  view_params = new LayoutParams(item_width, LayoutParams.WRAP_CONTENT);
		view_params.leftMargin = MobileUtils.dpToPx(6);
		view_params.rightMargin = MobileUtils.dpToPx(6);
		view.setLayoutParams(view_params);
		
		rl_doctor_talk_child = (RelativeLayout) view.findViewById(R.id.rl_doctor_talk_child);
		
		iv_doctor_talk_child = (AsyncImageView) view.findViewById(R.id.iv_doctor_talk_child);
		iv_doctor_talk_child.setBackgroundResource(0);
		tv_doctor_talk_child = (TextView) view.findViewById(R.id.tv_doctor_talk_child);
		
		final ImageView  supernatant = new ImageView(context);
		final RelativeLayout.LayoutParams  sup_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		sup_params.topMargin = MobileUtils.dpToPx(1);
		sup_params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
		supernatant.setLayoutParams(sup_params);
//		supernatant.setBackgroundResource(0);
		supernatant.setBackgroundResource(res);

		
		
		/**视图适配**/
		iv_doctor_talk_child.getLayoutParams().width = item_width - MobileUtils.dpToPx(12);
		iv_doctor_talk_child.getLayoutParams().height = MobileUtils.dpToPx((int)(item_iamge_width / 1.5));
		tv_doctor_talk_child.getLayoutParams().width = item_width - MobileUtils.dpToPx(12);
		
		rl_doctor_talk_child.addView(supernatant, sup_params);
		
		addView(view);
		
	}
}
